<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 创建连接
        let ws = new WebSocket('wss://javascript.info/article/websocket/demo/hello')
        // 监听连接
        ws.onopen = function(e){
            console.log('ok')
            // 向服务器发送请求
            ws.send('hillo')
        }

        // 监听服务器给客户端发送的请求
        ws.onmessage = function(e){
            console.log(e.data);
            // 关闭连接
            ws.close()
        }

        // 监听关闭事件
        ws.onclose = function(e){
            console.log('已关闭');
        }


        
    </script>
</body>
</html>